package com.ybkj.daijia.api.jgpt;

import com.google.gson.Gson;
import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.config.ZhuanApi;
import com.ybkj.daijia.server.mapper.GPSMapper;
import com.ybkj.daijia.server.model.GPS;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class orderAndGpsServiceImpl implements orderAndGpsService {

    public static Gson gson = new Gson();
    @Autowired
    GPSMapper gpsMapper;
    @Autowired
    private ZhuanApi zhuanApi;
    @Autowired
    private SettingUtils settingUtils;

    public String QueryOrder(String allstatus) {
        StringBuilder builder = new StringBuilder();
        builder.append(zhuanApi.getZhuanBaseURL()).append(ZhuanApi.QUERY_ORDERS)
            .append(".json?appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();

        if (StringUtils.isNotBlank(allstatus)) {
            kv.put("allstatus", allstatus);
            builder.append("&allstatus={allstatus}");
        }
        String result = zhuanApi.get(builder.toString(), kv, settingUtils.get());
        return result;
    }

    public String QueryGps() {
        List<GPS> gpsDataList = gpsMapper.selectAll();
        return gson.toJson(gpsDataList);
    }
}
